using JetBrains.Annotations;
using System;
using UnityEngine;

namespace FluffyUnderware.Curvy.ImportExport
{
	[Serializable]
	public class SerializedCurvySplineSegment
	{
		public Vector3 Position;

		public Vector3 Rotation;

		public bool AutoBakeOrientation;

		public bool OrientationAnchor;

		public CurvyOrientationSwirl Swirl;

		public float SwirlTurns;

		public bool AutoHandles;

		public float AutoHandleDistance;

		public Vector3 HandleOut;

		public Vector3 HandleIn;

		public SerializedCurvySplineSegment([NotNull] CurvySplineSegment segment, CurvySerializationSpace space)
		{
			Position = ((space != 0) ? segment.transform.localPosition : segment.transform.position);
			Rotation = ((space != 0) ? segment.transform.localRotation.eulerAngles : segment.transform.rotation.eulerAngles);
			AutoBakeOrientation = segment.AutoBakeOrientation;
			OrientationAnchor = segment.SerializedOrientationAnchor;
			Swirl = segment.Swirl;
			SwirlTurns = segment.SwirlTurns;
			AutoHandles = segment.AutoHandles;
			AutoHandleDistance = segment.AutoHandleDistance;
			HandleOut = segment.HandleOut;
			HandleIn = segment.HandleIn;
		}

		public void WriteIntoControlPoint([NotNull] CurvySplineSegment controlPoint, CurvySerializationSpace space)
		{
			if (space == CurvySerializationSpace.Global)
			{
				controlPoint.transform.position = Position;
				controlPoint.transform.rotation = Quaternion.Euler(Rotation);
			}
			else
			{
				controlPoint.transform.localPosition = Position;
				controlPoint.transform.localRotation = Quaternion.Euler(Rotation);
			}
			controlPoint.AutoBakeOrientation = AutoBakeOrientation;
			controlPoint.SerializedOrientationAnchor = OrientationAnchor;
			controlPoint.Swirl = Swirl;
			controlPoint.SwirlTurns = SwirlTurns;
			controlPoint.AutoHandles = AutoHandles;
			controlPoint.AutoHandleDistance = AutoHandleDistance;
			controlPoint.SetBezierHandleIn(HandleIn);
			controlPoint.SetBezierHandleOut(HandleOut);
		}
	}
}
